home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / C / MakeIndex < prev    next >
Text File  |  1998-08-26  |  6KB  |  186 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* Clear icon position */
  22. 'nopos' Volume'disk nodd'
  23. /* Delete trashcan */
  24. 'delete >NIL: 'Volume'Trashcan all force'
  25.  
  26. /* defines and such */
  27.         /* GREP CALL */
  28. GREPCALL = "grep"
  29.         /* GREP HELP CALL */
  30. GREPHELP = "grep -h"
  31.         /* Where's the CUCD index? */
  32. IDXLOC = 'CUCD:CDsupport/indices/'left(Volume,length(Volume) - 1)
  33.         /* Where's the finished guide to go to?*/
  34. outfile = 'CUCD:CDsupport/Docs.guide'
  35.         /* Path to MultiView */
  36. MView = Volume'Utilities/MultiView'
  37.         /* Extensions to search for */
  38. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  39.  
  40. if buildidx='Y' then do
  41.     /* NB the column format is important for the sort fuction later */
  42.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  43.     'list ' Volume'~(C|CDSupport|Classes|CUCD|Devs|Expansion|Fonts|L|Libs|Locale|Prefs|Rexxc|S|Storage|System|Tools|Utilities) all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  44.     'list ' Volume'CUCD/~(WWW) all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  45.     ';list' Volume'CUCD/WWW all files pat=~(#?.info) lformat "%-33N%P%N" >>'IDXLOC
  46.     end
  47.  
  48. grepfile = "t:grepoutput." || Pragma("i")
  49. agfile = "t:grepguide." || Pragma("i")
  50. CR      = d2c(10)
  51. TAB     = d2c(9)
  52.  
  53. /* setup the output file - we need this first so we can show errors in it */
  54. IF Open(agfp,agfile,'w') = 0 THEN DO
  55.         SAY "Couldn't create amigaguide file ("||agfile||")"
  56.         EXIT 20
  57.         END
  58.  
  59. call writeln(agfp,'@DATABASE "CD docs"')
  60. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  61. call writeln(agfp,'')
  62. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  63. call writeln(agfp,'')
  64.  
  65. /* Put a search button (needs searchguide in the CDs path) */
  66. if SGUIDE='Y' then do
  67. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  68. call writeln(agfp,'')
  69. end
  70.  
  71. SIGNAL ON FAILURE
  72. ADDRESS COMMAND
  73. 'delete >NIL:' grepfile
  74. do until Extensions = ''
  75.     parse var Extensions ext '|' Extensions
  76.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  77.     end
  78. 'rename' grepfile ' to ' grepfile||'.old'
  79. 'sort' grepfile||'.old' grepfile 'colstart 37'
  80. SIGNAL OFF FAILURE
  81.  
  82. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  83.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  84.         END
  85.  
  86. /*************************************************************************
  87. **  Format of Grep output
  88. **  =====================
  89. **
  90. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  91. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  92. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  93. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  94. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  95. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  96. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  97. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  98. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  99. **
  100. ****************************************************************************/
  101.  
  102. line = ReadLn(grepfp)
  103. IF EOF(grepfp) THEN DO
  104.         call close(grepfp)
  105.         say 'No files found'
  106.         exit 10
  107.         END
  108.  
  109.  
  110.         CALL Pragma('W','n')            /* turn off dos requesters */
  111.  
  112. DO WHILE ~EOF(grepfp)
  113.         /* START BY LOOKING FOR FILENAMES */
  114.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  115.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  116.         if right(currentfile,5) ='guide' then
  117.         do
  118.             node='/main'
  119.             action='link "'
  120.         end
  121.         else
  122.         do
  123.             node=''
  124.             action='system "'MView' '
  125.         end
  126.         endif
  127.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  128.         line = ReadLn(grepfp)
  129.                 END
  130.  
  131. call WriteLn(agfp,'@ENDNODE')
  132.  
  133. call Close(grepfp)
  134. call Close(agfp)
  135.  
  136.        CALL Pragma('W','w')            /* turn dos requesters back on */
  137.  
  138. address command
  139. 'copy' agfile outfile
  140. 'delete >NIL:' grepfile
  141. 'delete >NIL:' grepfile||'.old'
  142. 'delete >NIL:' agfile
  143.  
  144. EXIT
  145.  
  146. FAILURE:
  147. ERROR:
  148.         errRC = RC
  149.         CALL Close(grepfp)
  150.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  151.         EXIT
  152.  
  153. /***************************************************/
  154. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  155.  
  156.         ErrorText = arg(1)
  157.         ErrorFile = arg(2)
  158.  
  159.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  160.         call writeln(agfp,ErrorText)
  161.         call writeln(agfp,' ')
  162.  
  163.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  164.                 call writeln(agfp,"Response:")
  165.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  166.                 Open('errorfp',ErrorFile,'r')
  167.                 DO WHILE ~EOF('errorfp')
  168.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  169.                         END
  170.                 call close('errorfp')
  171.                 END
  172.  
  173.         call writeln(agfp,"")
  174.         call writeln(agfp,"Current Path:")
  175.         call writeln(agfp,"    "||Pragma("D"))
  176.         call writeln(agfp,'@ENDNODE')
  177.  
  178.         call close(agfp)
  179.  
  180.         IF Exists(grepfile) THEN Delete(grepfile)
  181.         Delete(agfile)
  182.  
  183.         EXIT 20
  184. RETURN
  185.  
  186.